// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects

import Fk
import "../../components" as QsgsComponents

Item {
  id: root
  property int value: defaultValue ?? from ?? 0
  property int defaultValue
  property string skill

  property int from
  property int to

  width: childrenRect.width
  height: childrenRect.height

  Glow {
    id: rowGlow
    source: spinBoxRow
    anchors.fill: spinBoxRow
    color: '#000000'
    spread: 0.9
    radius: 1.5
  }

  Row {
    id: spinBoxRow
    spacing: 3
    QsgsComponents.ImageButton {
      width: 20
      height: 20
      source: Cpp.path + "/packages/lunarltk-qsgs-ui/image/selfArea/subtract.png"

      onClicked: {
        if (root.value > root.from) {
          root.value += -1;
        }
      }
    }

    Image {
      source: Cpp.path + "/packages/lunarltk-qsgs-ui/image/selfArea/interaction-spin.png"
      height: 20
      fillMode: Image.PreserveAspectFit

      Text {
        text: String(root.value)
        anchors.centerIn: parent
        font.bold: true
        color: "white"
      }
    }

    QsgsComponents.ImageButton {
      width: 20
      height: 20
      source: Cpp.path + "/packages/lunarltk-qsgs-ui/image/selfArea/add.png"

      onClicked: {
        if (root.value < root.to) {
          root.value += 1;
        }
      }
    }
  }
  

  onValueChanged: {
    Lua.call("UpdateRequestUI", "Interaction", "1", "update", value);
  }
}
